# !/usr/bin python3
# encoding: utf-8 -*-
# @file     : run.py
# @author   : 沙陌 Matongxue_2
# @Time     : 2023/12/26 21:48
# @Copyright: 北京码同学
import os
import sys

import pytest

from common.file_load import load_yaml_file, write_yaml
from paths_manager import common_yaml_path, http_yaml_path, db_yaml_path, redis_yaml_path

if __name__ == '__main__':
    args = sys.argv
    print(args) # ['run.py', 'uat']
    # 给env_file一个默认值，是为了兼容不传递环境名称时，默认执行test环境
    env_file = 'config/env_test.yml'
    if len(args)>1:
        env_name = args[1]
        env_file = f'config/env_{env_name}.yml'
        del args[1] # 删除传进来的环境名称参数，否则会被当做pytest要执行的测试用例名称

    env_info = load_yaml_file(env_file)
    # 依次写入各个配置文件中去
    write_yaml(common_yaml_path,env_info['common'])
    write_yaml(http_yaml_path, env_info['http'])
    write_yaml(db_yaml_path, env_info['db'])
    write_yaml(redis_yaml_path, env_info['redis'])
    # pytest.main会自动扫描pytest.ini中相关的配置
    pytest.main()
    # # 执行完成后自动打开测试报告
    os.system('allure serve report/data')
    # 这是A的修改
    # 这是B的修改
    # 这是分支1的修改